<?php

/**
 * This is the model class for table "m_customer_hpayment".
 *
 * The followings are the available columns in table 'm_customer_hpayment':
 * @property integer $id
 * @property string $payment_no
 * @property string $payment_date
 * @property integer $customer_id
 * @property integer $receive_acc_id
 * @property string $ttl_payment
 * @property string $notes
 * @property integer $jurnal_id
 * @property string $input_date_time
 * @property integer $user_id
 * @property integer $is_active
 *
 * The followings are the available model relations:
 * @property MCustomerDpayment[] $mCustomerDpayments
 * @property MUser $user
 * @property MCustomer $customer
 * @property MCoa $receiveAcc
 */
class MCustomerHpayment extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'm_customer_hpayment';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('payment_no, payment_date, customer_id, receive_acc_id, ttl_payment, jurnal_id, input_date_time, user_id, is_active', 'required'),
			array('customer_id, receive_acc_id, jurnal_id, user_id, is_active', 'numerical', 'integerOnly'=>true),
			array('payment_no', 'length', 'max'=>100),
			array('ttl_payment', 'length', 'max'=>14),
			array('notes', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, payment_no, payment_date, customer_id, receive_acc_id, ttl_payment, notes, jurnal_id, input_date_time, user_id, is_active', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'mCustomerDpayments' => array(self::HAS_MANY, 'MCustomerDpayment', 'customer_payment_id'),
			'user' => array(self::BELONGS_TO, 'MUser', 'user_id'),
			'customer' => array(self::BELONGS_TO, 'MCustomer', 'customer_id'),
			'receiveAcc' => array(self::BELONGS_TO, 'MCoa', 'receive_acc_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'payment_no' => 'Payment No',
			'payment_date' => 'Payment Date',
			'customer_id' => 'Customer',
			'receive_acc_id' => 'Receive Acc',
			'ttl_payment' => 'Ttl Payment',
			'notes' => 'Notes',
			'jurnal_id' => 'Jurnal',
			'input_date_time' => 'Input Date Time',
			'user_id' => 'User',
			'is_active' => 'Is Active',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('payment_no',$this->payment_no,true);
		$criteria->compare('payment_date',$this->payment_date,true);
		$criteria->compare('customer_id',$this->customer_id);
		$criteria->compare('receive_acc_id',$this->receive_acc_id);
		$criteria->compare('ttl_payment',$this->ttl_payment,true);
		$criteria->compare('notes',$this->notes,true);
		$criteria->compare('jurnal_id',$this->jurnal_id);
		$criteria->compare('input_date_time',$this->input_date_time,true);
		$criteria->compare('user_id',$this->user_id);
		$criteria->compare('is_active',$this->is_active);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return MCustomerHpayment the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
